﻿using System;
using System.Collections.Generic;
using System.IO;

namespace LogWriter
{
    public class LogWriter
    {
        private void WriteLog(String log, StreamWriter sw)
        {
            sw.WriteLine("{0}\t{1}", DateTime.Now.ToString(), log);
        }
        public void WriteLog(String log, String file)
        {
            FileStream fs = new FileStream(file, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            try
            {
                WriteLog(log, sw);
            }
            catch (Exception err)
            {
                throw err;
            }
            finally
            {
                sw.Flush();
                sw.Close();
                if (fs.CanWrite)
                {
                    fs.Flush();
                }
                fs.Close();
                sw.Dispose();
                fs.Dispose();
            }
        }
        public void WriteLog(List<string> data, string file)
        {
            FileStream fs = new FileStream(file, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            try
            {
                foreach (string s in data)
                {
                    WriteLog(s, sw);
                }
            }
            catch (Exception err)
            {
                throw err;
            }
            finally
            {
                sw.Flush();
                sw.Close();
                if (fs.CanWrite)
                {
                    fs.Flush();
                }
                fs.Close();
                sw.Dispose();
                fs.Dispose();
            }
        }
    }
}
